package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.entity.vo.QueryTradeParam;
import io.renren.modules.app.entity.vo.SelectTradeData;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.app.entity.TradeRecordingEntity;
import io.renren.modules.app.service.TradeRecordingService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 交易记录表
 *
 *
 *
 * @date 2022-04-20 22:37:44
 */
@RestController
@RequestMapping("app/traderecording")
public class TradeRecordingController {
    @Autowired
    private TradeRecordingService tradeRecordingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:traderecording:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tradeRecordingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tradeId}")
    @RequiresPermissions("generator:traderecording:info")
    public R info(@PathVariable("tradeId") Long tradeId){
		TradeRecordingEntity tradeRecording = tradeRecordingService.getById(tradeId);

        return R.ok().put("tradeRecording", tradeRecording);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:traderecording:save")
    public R save(@RequestBody TradeRecordingEntity tradeRecording){
        tradeRecording.setCreateTime(new Date());
		tradeRecordingService.save(tradeRecording);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:traderecording:update")
    public R update(@RequestBody TradeRecordingEntity tradeRecording){
		tradeRecordingService.updateById(tradeRecording);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:traderecording:delete")
    public R delete(@RequestBody Long[] tradeIds){
		tradeRecordingService.removeByIds(Arrays.asList(tradeIds));

        return R.ok();
    }

    /**
     * 获取交易记录
     */
    @Login
    @GetMapping("/queryGradeList")
    public R queryGradeList(QueryTradeParam tradeRecording){
        SelectTradeData selectTradeData = tradeRecordingService.queryTradeRecordingList(tradeRecording);
        return R.ok().put("tradeData", selectTradeData);
    }


}
